import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'login',
    // 路由懒加载
    component: () => import('@/views/login')
  },
  {
    path: '/',
    name: 'tab-bar',
    component: () => import('@/views/layout'),
    meta: {
      keepAlive: true
    },
    children: [
      {
        path: '', // 默认子路由
        name: 'home',
        component: () => import('@/views/home'),
        // 配置需要缓存的组件
        meta: {
          keepAlive: true
        }
      },
      {
        path: 'qa',
        name: 'qa',
        component: () => import('@/views/qa')
      },
      {
        path: 'video',
        name: 'video',
        component: () => import('@/views/video')
      },
      {
        path: 'my',
        name: 'my',
        component: () => import('@/views/my')
      },
      {
        path: '/search',
        component: () => import('@/views/search')
      }
    ]
  },
  {
    path: '/article/:articleId',
    name: 'article',
    component: () => import('@/views/article'),
    // 将路由动态参数映射到组件的 props 中，更推荐这种做法
    props: true
  },
  {
    path: '/profile',
    name: 'profile',
    component: () => import('@/views/profile')
  },
  {
    path: '/collections',
    name: 'collections',
    component: () => import('@/views/collections')
  },
  {
    path: '/histories',
    name: 'histories',
    component: () => import('@/views/histories')
  },
  {
    path: '/followings',
    name: 'followings',
    component: () => import('@/views/followings')
  },
  {
    path: '/followers',
    name: 'followers',
    component: () => import('@/views/followers')
  },
  {
    path: '/toUser',
    name: 'toUser',
    component: () => import('@/views/toUser')
  },
  {
    path: '/gonggao',
    name: 'gonggao',
    component: () => import('@/views/gonggao')
  },
  {
    path: '/xiaozhi',
    name: 'xiaozhi',
    component: () => import('@/views/xiaozhi')
  }
]

const router = new VueRouter({
  routes
})

export default router
